﻿package frEngine.core.lenses
{
    import __AS3__.vec.*;

    public class PerspectiveLens extends LensBase
    {
        private var _fieldOfView:Number;
        private var _zoom:Number;
        private var _yMax:Number;
        private var _xMax:Number;
        private static const RAW_DATA_CONTAINER:Vector.<Number> = new Vector.<Number>(16);

        public function PerspectiveLens(param1:Number = 60)
        {
            this.fieldOfView = param1;
            return;
        }// end function

        public function get fieldOfView() : Number
        {
            return this._fieldOfView;
        }// end function

        public function set fieldOfView(param1:Number) : void
        {
            if (param1 == this._fieldOfView)
            {
                return;
            }
            this._fieldOfView = param1;
            this._zoom = Math.tan(this._fieldOfView * Math.PI / 360);
            invalidateMatrix();
            return;
        }// end function

        override public function clone() : LensBase
        {
            var _loc_1:* = new PerspectiveLens(this._fieldOfView);
            _loc_1._near = _near;
            _loc_1._far = _far;
            _loc_1._aspectRatio = _aspectRatio;
            return _loc_1;
        }// end function

        override protected function updateMatrix() : void
        {
            var _loc_1:* = RAW_DATA_CONTAINER;
            var _loc_2:* = 1 / this._zoom * _aspectRatio;
            var _loc_3:* = _loc_2 / _aspectRatio;
            _loc_1[0] = _loc_3;
            _loc_1[5] = _loc_2;
            _loc_1[10] = far / (far - near);
            _loc_1[11] = 1;
            _loc_1[14] = (-near) * _loc_1[10];
            var _loc_4:int = 0;
            _loc_1[15] = 0;
            var _loc_4:* = _loc_4;
            _loc_1[13] = _loc_4;
            var _loc_4:* = _loc_4;
            _loc_1[12] = _loc_4;
            var _loc_4:* = _loc_4;
            _loc_1[9] = _loc_4;
            var _loc_4:* = _loc_4;
            _loc_1[8] = _loc_4;
            var _loc_4:* = _loc_4;
            _loc_1[7] = _loc_4;
            var _loc_4:* = _loc_4;
            _loc_1[6] = _loc_4;
            var _loc_4:* = _loc_4;
            _loc_1[4] = _loc_4;
            var _loc_4:* = _loc_4;
            _loc_1[3] = _loc_4;
            var _loc_4:* = _loc_4;
            _loc_1[2] = _loc_4;
            _loc_1[1] = _loc_4;
            _matrix.copyRawDataFrom(_loc_1);
            _matrixInvalid = false;
            return;
        }// end function

    }
}
